package com.yb.xczx.cloud.auth.oauth2.handler.mybatis;

import org.springframework.security.oauth2.core.AuthorizationGrantType;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/21 15:37
 * FileName: XczxClientAuthenticationMethodSetTypeHandler
 * Description:
 */
public class XczxAuthorizationGrantTypeSetTypeHandler extends XczxSetTypeHandler<AuthorizationGrantType> {
    @Override
    protected AuthorizationGrantType getResult(String resultStr) {
        return resolveAuthorizationGrantType(resultStr);
    }

    @Override
    protected String itemToString(AuthorizationGrantType authorizationGrantType) {
        return authorizationGrantType.getValue();
    }

    private static AuthorizationGrantType resolveAuthorizationGrantType(String authorizationGrantType) {
        if (AuthorizationGrantType.AUTHORIZATION_CODE.getValue().equals(authorizationGrantType)) {
            return AuthorizationGrantType.AUTHORIZATION_CODE;
        } else if (AuthorizationGrantType.CLIENT_CREDENTIALS.getValue().equals(authorizationGrantType)) {
            return AuthorizationGrantType.CLIENT_CREDENTIALS;
        } else if (AuthorizationGrantType.REFRESH_TOKEN.getValue().equals(authorizationGrantType)) {
            return AuthorizationGrantType.REFRESH_TOKEN;
        }
        return new AuthorizationGrantType(authorizationGrantType);		// Custom authorization grant type
    }


}
